﻿<cfsilent>
	<cfscript>
		
		event.setArg("pageTitle", "学生选课管理 - 添加课程向导");
		
		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		mathAdvice = getProperty("serviceFactory").getBean("senateMathAdvice");
		
		stuId = event.getArg("STU");
		termId = event.getArg("TermID", event.getArg("TID"));
		
		targetArgs = structNew();
		structInsert(targetArgs, "STU", stuId, true);
		structInsert(targetArgs, "TabID", "labChooseTable", true);
		
		passArg = structNew();
		
		if ( len(stuId) ) {
			structInsert( passArg, "STU", stuId, true );
		}
		if ( len(termId) ) {
			structInsert( passArg, "TID", termId, true );
			structInsert( targetArgs, "TID", termId, true );
		}

		currentTab = event.getArg("TabID", "labSearch");
		
		/* 搜索课程教学班 */
		courseKeyword = event.getArg("Keywords");
		courseType = event.getArg("TT");
	
		courseArray = [];
		
		rs_task = queryNew("tsk_id");
		
		if ( len(courseKeyword) ) {
			
			switch ( courseType ) {
				
				case "P":
					sql = "SELECT 
								a.tsk_id, 
								t_course.cid, 
								t_course.course_name, 
								t_course.course_code, 
								t_institute.institute_short, 
								t_course.course_credit, 
								a.cidx, 
								t_teacher.tch_name, 
								a.task_limite, 
								a.task_chooesd, 
								t_campus.campus_name, 
								a.task_week, 
								CASE WHEN a.task_time IS NULL THEN '-' ELSE a.task_time END task_time, 
								CASE WHEN a.task_place IS NULL THEN '-' ELSE a.task_place END task_place, 
								'P' tt, 
								a.task_prop 
							FROM 
								t_task a
								INNER JOIN t_course ON t_course.cid = a.cid 
								INNER JOIN t_institute ON t_institute.institute_id = t_course.institute_id 
								INNER JOIN t_teacher ON t_teacher.tch_id = a.tch_id 
								INNER JOIN t_campus ON t_campus.campus_id = a.campus_id 
							WHERE 
								a.term_id = :termId 
								AND 
								(t_course.course_name LIKE :condition OR t_course.course_code LIKE :condition) 
								AND 
								(a.task_chooesd < a.task_limite) 
								AND 
								SUBSTR(a.task_prop, 3, 1) = '0' 
								AND 
								SUBSTR(a.task_prop, 7, 1) = '0'
								AND 
								EXISTS(
									  SELECT 1 FROM t_task_arrange b WHERE b.task_id = a.tsk_id AND b.term_id = :termId 
								)
							ORDER BY 
								t_course.course_name, a.cidx ";
					
					break;
					
				case "C":
					sql = "SELECT 
								a.tsk_id, 
								t_course.cid, 
								t_course.course_name, 
								t_course.course_code, 
								t_institute.institute_short, 
								t_course.course_credit, 
								a.cidx, 
								t_teacher.tch_name, 
								a.task_limite, 
								a.task_chooesd, 
								t_campus.campus_name, 
								a.task_week, 
								CASE WHEN a.task_time IS NULL THEN '-' ELSE a.task_time END task_time, 
								CASE WHEN a.task_place IS NULL THEN '-' ELSE a.task_place END task_place, 
								'C' tt, 
								a.task_prop 
							FROM 
								t_common_task a
								INNER JOIN t_course ON t_course.cid = a.cid 
								INNER JOIN t_institute ON t_institute.institute_id = t_course.institute_id 
								INNER JOIN t_teacher ON t_teacher.tch_id = a.tch_id 
								INNER JOIN t_campus ON t_campus.campus_id = a.campus_id 
							WHERE 
								a.term_id = :termId 
								AND 
								(t_course.course_name LIKE :condition OR t_course.course_code LIKE :condition) 
								AND 
								(a.task_chooesd < a.task_limite) 
								AND 
								SUBSTR(a.task_prop, 3, 1) = '0' 
								AND 
								SUBSTR(a.task_prop, 7, 1) = '0'
								AND 
								EXISTS(
									  SELECT 1 FROM t_task_arrange b WHERE b.task_id = a.tsk_id AND b.term_id = :termId 
								)
							ORDER BY 
								t_course.course_name, a.cidx ";
					break;
				
				case "T":
					sql = "SELECT 
								a.tsk_id, 
								t_course.cid, 
								t_course.course_name, 
								t_course.course_code, 
								t_institute.institute_short, 
								t_course.course_credit, 
								a.cidx, 
								t_teacher.tch_name, 
								a.task_limite, 
								a.task_chooesd, 
								t_campus.campus_name, 
								a.task_week, 
								CASE WHEN a.task_time IS NULL THEN '-' ELSE a.task_time END task_time, 
								CASE WHEN a.task_place IS NULL THEN '-' ELSE a.task_place END task_place, 
								'T' tt, 
								a.task_prop 
							FROM 
								t_sport_task a
								INNER JOIN t_course ON t_course.cid = a.cid 
								INNER JOIN t_institute ON t_institute.institute_id = t_course.institute_id 
								INNER JOIN t_teacher ON t_teacher.tch_id = a.tch_id 
								INNER JOIN t_campus ON t_campus.campus_id = a.campus_id 
							WHERE 
								a.term_id = :termId 
								AND 
								(t_course.course_name LIKE :condition OR t_course.course_code LIKE :condition) 
								AND 
								(a.task_chooesd < a.task_limite) 
								AND 
								SUBSTR(a.task_prop, 7, 1) = '0' 
								AND 
								EXISTS(
									  SELECT 1 FROM t_task_arrange b WHERE b.task_id = a.tsk_id AND b.term_id = :termId 
								)
							ORDER BY 
								t_course.course_name, a.cidx ";

												/*
														教务处可以向 设置为禁止学生选课的课程 添加选课名单
														and 
														substring(TaskProps, 3, 1) = '0'
												*/
					
					break;
				
				case "R":
					sql = "SELECT 
								a.tsk_id, 
								t_course.cid, 
								t_course.course_name, 
								t_course.course_code, 
								t_institute.institute_short, 
								t_course.course_credit, 
								a.cidx, 
								t_teacher.tch_name, 
								a.task_limite, 
								a.task_chooesd, 
								t_campus.campus_name, 
								a.task_week, 
								CASE WHEN a.task_time IS NULL THEN '-' ELSE a.task_time END task_time, 
								CASE WHEN a.task_place IS NULL THEN '-' ELSE a.task_place END task_place, 
								'R' tt, 
								a.task_prop 
							FROM 
								t_reopen_task a
								INNER JOIN t_course ON t_course.cid = a.cid 
								INNER JOIN t_institute ON t_institute.institute_id = t_course.institute_id 
								INNER JOIN t_teacher ON t_teacher.tch_id = a.tch_id 
								INNER JOIN t_campus ON t_campus.campus_id = a.campus_id 
							WHERE 
								a.term_id = :termId 
								AND 
								(t_course.course_name LIKE :condition OR t_course.course_code LIKE :condition) 
								AND 
								(a.task_chooesd < a.task_limite) 
								AND 
								SUBSTR(a.task_prop, 3, 1) = '0' 
								AND 
								SUBSTR(a.task_prop, 7, 1) = '0'
								AND 
								EXISTS(
									  SELECT 1 FROM t_task_arrange b WHERE b.task_id = a.tsk_id AND b.term_id = :termId 
								)
							ORDER BY 
								t_course.course_name, a.cidx ";
								
					break;
					
			}
			
			queryObj = new query( datasource=application.dnsSlave );
			queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="condition", value=courseKeyword & '%', cfsqltype="cf_sql_varchar" );
			rs_task = queryObj.execute( sql=sql ).getResult();
						
		}
		
		if ( rs_task.recordCount ) {

			currentTab = event.getArg("TabID", "labWizard");

			for (i = 1; i LTE rs_task.recordCount; i++){
				
				course = [ rs_task["cid"][i], rs_task["course_name"][i], rs_task["institute_short"][i], rs_task["course_code"][i], rs_task["course_credit"][i] ];		
				if ( not arrayFind( courseArray, course ) ) {
					arrayAppend(courseArray, course);	
				}
			}
		}

		
		taskId = event.getArg("TSK");
		taskType = event.getArg("TT");
		rs_taskSet = queryNew("course_name");
	
		if ( len(taskId) and len(taskType) ) {
			
			switch(taskType){
				case "C":
					sql = "SELECT 
								t_course.course_name, 
								t_institute.institute_short, 
								t_course.course_code, 
								t_course.course_credit, 
								a.cidx, 
								t_teacher.tch_name, 
								a.task_limite, 
								a.task_chooesd, 
								t_campus.campus_name, 
								a.task_week, 
								a.task_time, 
								a.task_place 
							FROM 
								t_common_task a
								INNER JOIN t_course ON t_course.cid = a.cid 
								INNER JOIN t_institute ON t_institute.institute_id = t_course.institute_id 
								INNER JOIN t_teacher ON t_teacher.tch_id = a.tch_id 
								INNER JOIN t_campus ON t_campus.campus_id = a.campus_id 
							WHERE 
								a.tsk_id = :taskId ";
					break;
	
				case "P":
					sql = "SELECT 
								t_course.course_name, 
								t_institute.institute_short, 
								t_course.course_code, 
								t_course.course_credit, 
								a.cidx, 
								t_teacher.tch_name, 
								a.task_limite, 
								a.task_chooesd, 
								t_campus.campus_name, 
								a.task_week, 
								a.task_time, 
								a.task_place 
							FROM 
								t_task a
								INNER JOIN t_course ON t_course.cid = a.cid 
								INNER JOIN t_institute ON t_institute.institute_id = t_course.institute_id 
								INNER JOIN t_teacher ON t_teacher.tch_id = a.tch_id 
								INNER JOIN t_campus ON t_campus.campus_id = a.campus_id 
							WHERE 
								a.tsk_id = :taskId ";
					break;
				
				case "R":
					sql = "SELECT 
								t_course.course_name, 
								t_institute.institute_short, 
								t_course.course_code, 
								t_course.course_credit, 
								a.cidx, 
								t_teacher.tch_name, 
								a.task_limite, 
								a.task_chooesd, 
								t_campus.campus_name, 
								a.task_week, 
								a.task_time, 
								a.task_place 
							FROM 
								t_reopen_task a
								INNER JOIN t_course ON t_course.cid = a.cid 
								INNER JOIN t_institute ON t_institute.institute_id = t_course.institute_id 
								INNER JOIN t_teacher ON t_teacher.tch_id = a.tch_id 
								INNER JOIN t_campus ON t_campus.campus_id = a.campus_id 
							WHERE 
								a.tsk_id = :taskId ";
					break;
				
				case "T":
					sql = "SELECT 
								t_course.course_name, 
								t_institute.institute_short, 
								t_course.course_code, 
								t_course.course_credit, 
								a.cidx, 
								t_teacher.tch_name, 
								a.task_limite, 
								a.task_chooesd, 
								t_campus.campus_name, 
								a.task_week, 
								a.task_time, 
								a.task_place 
							FROM 
								t_sport_task a
								INNER JOIN t_course ON t_course.cid = a.cid 
								INNER JOIN t_institute ON t_institute.institute_id = t_course.institute_id 
								INNER JOIN t_teacher ON t_teacher.tch_id = a.tch_id 
								INNER JOIN t_campus ON t_campus.campus_id = a.campus_id 
							WHERE 
								a.tsk_id = :taskId ";
					break;
			}
			queryObj = new query( datasource=application.dnsSlave );
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
			rs_taskSet = queryObj.execute( sql=sql ).getResult();
		}
		
		if ( rs_taskSet.recordCount ) {
			currentTab = event.getArg("TabID", "labWizardDone");
		}
		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('modifyStudentCourse', targetArgs)#</cfoutput>"><i class="mrs img btnList"></i><span class="uiButtonText">学生课表调整</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 info"></i>确认要添加的课程
				</h2>
			</div>
		</div>
	</div>
</div>

<!--- 加载导航菜单 --->
<!-- stepMenu-->
<cfoutput>#event.getArg("stepMenu")#</cfoutput>
<!--/stepMenu-->

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="programCourse">
				<div class="UItab2">
					<div class="tabLables">
						<span <cfif currentTab eq "labSearch">class="active"</cfif> id="labSearch" tabTarget="Search">搜索课程</span>
						<cfif rs_task.recordCount>
							<span <cfif currentTab eq "labWizard">class="active"</cfif> id="labWizard" tabTarget="Wizard">选择课程及授课教师</span>
						</cfif>
						<cfif rs_taskSet.recordCount>
							<span <cfif currentTab eq "labWizardDone">class="active"</cfif> id="labWizardDone" tabTarget="WizardDone">已选择的教学班</span>
						</cfif>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					
					// -->
					//]]>
				</script>
				
				<div id="Search" class="tabContent">
					
					<form id="formSearch" onSubmit="javascript:return processVerfiyForm('formSearch');" class="formWrapper" method="post" action="<cfoutput>#buildURL('applyWizardByStudent', passArg)#</cfoutput>">
						
						<div class="label">
							<b>课程</b>
							<input name="Keywords" id="Keywords" type="text" class="typeTextShort" verification="required" maxlength="30" value="<cfoutput>#event.getArg('Keywords')#</cfoutput>" />
							<p class="notice">在这里输入课程号 或 课程中文名称, 用于查找已开设的教学班</p>
						</div>
						
						<div class="label">
							<b>开课类别</b>
							<select name="TT">
								<option value="P">计划课程</option>
								<option value="C">全校通选课</option>
								<option value="T">体育项目</option>
								<option value="R">单开班课程</option>
							</select>
						</div>
						
						<hr/>
						<div class="lable">
							<input class="button4" type="submit" value="搜索" />
							<input id="formReset" class="button" type="reset" value="重设表格" />
						</div>
					</form>
					
				</div>
				
				<div id="Wizard" class="tabContent">
					
                    
					<cfloop array="#courseArray#" index="course">
                    
						<div class="noticeBlock">
							<h3><cfoutput>#course[2]#</cfoutput></h3>
							<p>任课单位 <cfoutput>#course[3]#</cfoutput> <cfif course[4] neq "-">课程号 <em><cfoutput>#course[4]#</cfoutput></em></cfif> 学分 <em><cfoutput>#numberFormat( course[5], "_.__" )#</cfoutput></em></p>
							<hr/>
						</div>
						
						<table class="UIEditable">
							<thead>
								<tr>
									<td width="30"></td>
									<td width="70">开课类别</td>
									<td width="40">课序号</td>
									<td>教师</td>
									<td width="40">席位</td>
									<td width="60">校区</td>
									<td width="80">周次</td>
									<td width="180">上课时间</td>
									<td>上课地点</td>
								</tr>
							</thead>
							<tbody>
                                <cfloop query="rs_task">
									<cfif rs_task.cid eq course[1]>
										
										<cfset structInsert( passArg, "TSK", rs_task.tsk_id, true ) />
										<cfset structInsert( passArg, "TT", rs_task.tt, true ) />
										
										<tr class="editRows">
											<td>
												<cfif event.isArgDefined("STU")>
													<a class="stat off" href="<cfoutput>#buildURL('applyWizardByStudentDetail', passArg)#</cfoutput>"></a>
												</cfif>
											</td>
											<td><cfoutput>#dictAdvice.getTaskType( rs_task.tt )#</cfoutput></td>
											<td><span class="index"><cfoutput>#rs_task.cidx#</cfoutput></span></td>
											<td><cfoutput>#rs_task.tch_name#</cfoutput></td>
											
											<td><span class="numeric"><cfoutput>#rs_task.task_limite-rs_task.task_chooesd#</cfoutput></span></td>
											<td><cfoutput>#rs_task.campus_name#</cfoutput></td>
											<td><span class="numeric"><cfoutput>#rs_task.task_week#</cfoutput></span></td>
											<td><cfoutput>#replace(mathAdvice.convertTaskTime(rs_task.task_time), ",", "<br/>", "all")#</cfoutput></td>
											<td><cfoutput>#replace(rs_task.task_place, ",", "<br/>", "all")#</cfoutput></td>
										</tr>
										
										<cfset structDelete( passArg, "TSK" ) />
										<cfset structDelete( passArg, "TT" ) />
									</cfif>
								</cfloop>
							</tbody>
						</table>
						
					</cfloop>
					
				</div>
				
				<div id="WizardDone" class="tabContent">
					
					<cfif rs_taskSet.recordCount>
					
						<div class="noticeBlock">
							<h3><cfoutput>#rs_taskSet.course_name#</cfoutput></h3>
							<p>任课单位 <cfoutput>#rs_taskSet.institute_short#</cfoutput> <cfif rs_taskSet.course_code neq "-">课程号 <em><cfoutput>#rs_taskSet.course_code#</cfoutput></em></cfif> 学分 <em><cfoutput>#numberFormat( rs_taskSet.course_credit, "_.__" )#</cfoutput></em></p>
							<hr/>
						</div>
						
						<table class="UIEditable">
							<thead>
								<tr>
									<td width="40">课序号</td>
									<td width="160">教师</td>
									<td width="40">席位</td>
									<td width="60">校区</td>
									<td width="80">周次</td>
									<td width="180">上课时间</td>
									<td>上课地点</td>
								</tr>
							</thead>
							<tbody>
								<tr class="editRows">
									<td class="index"><cfoutput>#rs_taskSet.cidx#</cfoutput></td>
									<td><cfoutput>#rs_taskSet.tch_name#</cfoutput></td>
									<td><span class="numeric"><cfoutput>#rs_taskSet.task_limite-rs_taskSet.task_chooesd#</cfoutput></span></td>
									<td><cfoutput>#rs_taskSet.campus_name#</cfoutput></td>
									<td><span class="numeric"><cfoutput>#rs_taskSet.task_week#</cfoutput></span></td>
									<td><cfif len(rs_taskSet.task_time)><cfoutput>#replace( mathAdvice.convertTaskTime( rs_taskSet.task_time ), ",", "<br/>", "ALL")#</cfoutput></cfif></td>
									<td><cfoutput>#replace( rs_taskSet.task_place, ",", "<br/>", "ALL")#</cfoutput></td>
								</tr>
							</tbody>
						</table>
						
					</cfif>
				</div>
				
				
			</div>
		</li>
	</ul>
</div>